home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Gfx / Edit / TSMorph / src / gui.c < prev    next >
C/C++ Source or Header  |  1994-10-30  |  32KB  |  1,003 lines

  1. // TSMorph - Amiga Morphing program
  2. // Copyright (C) © 1993  Topicsave Limited
  3.  
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // any later version.
  8.  
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. // GNU General Public License for more details.
  13.  
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. // mpaddock@cix.compulink.co.uk
  19.  
  20. /*
  21.  *  Source machine generated by GadToolsBox V2.0
  22.  *  which is (c) Copyright 1991-1993 Jaba Development
  23.  *
  24.  *  GUI Designed by : M J P
  25.  */
  26.  
  27. // Note! This has had some source code changes after GadToolsBox generation
  28. // including joining sources together, changing/adding gadgets
  29. // and other source code (etc.) !!!!!
  30. // Most changes should have comments attached
  31.  
  32. // include headers if not already done so
  33. #ifndef TSMORPH_H
  34. #include "TSMorph.h"
  35. #endif
  36.  
  37. struct Screen         *Scr = NULL;
  38. UBYTE                 *PubScreenName = NULL;
  39. APTR                   VisualInfo = NULL;
  40. struct Window         *TSMorphWnd = NULL;
  41. struct Gadget         *TSMorphGList = NULL;
  42. struct Menu           *TSMorphMenus = NULL;
  43. struct MenuItem       *TSMorphMenus1 = NULL;
  44. struct IntuiMessage    TSMorphMsg;
  45. UWORD                  TSMorphZoom[4];
  46. struct Gadget         *TSMorphGadgets[17];
  47. extern Class          *initGet( void );
  48. struct IClass         *getClass = NULL;
  49. struct _Object        *getImage = NULL;
  50. UWORD                  TSMorphLeft = 0;
  51. UWORD                  TSMorphTop = 15;
  52. UWORD                  TSMorphWidth = 262;
  53. UWORD                  TSMorphHeight = 169;
  54. UBYTE                 *TSMorphWdt = (UBYTE *)"TSMorph";
  55. struct TextAttr       *Font, Attr;
  56. UWORD                  FontX, FontY;
  57. UWORD                  OffX, OffY;
  58.  
  59. struct Window         *GridRequestWnd = NULL;
  60. struct Gadget         *GridRequestGList = NULL;
  61. struct IntuiMessage    GridRequestMsg;
  62. struct Gadget         *GridRequestGadgets[4];
  63. UWORD                  GridRequestLeft = 246;
  64. UWORD                  GridRequestTop = 21;
  65. UWORD                  GridRequestWidth = 121;
  66. UWORD                  GridRequestHeight = 61;
  67. UBYTE                 *GridRequestWdt = (UBYTE *)"Add Grid";
  68.  
  69. struct Window         *ProgressWnd = NULL;
  70. struct Gadget         *ProgressGList = NULL;
  71. struct IntuiMessage    ProgressMsg;
  72. struct Gadget         *ProgressGadgets[3];
  73. UWORD                  ProgressLeft = 190;
  74. UWORD                  ProgressTop = 42;
  75. UWORD                  ProgressWidth = 311;
  76. UWORD                  ProgressHeight = 57;
  77. UBYTE                 *ProgressWdt = (UBYTE *)"Loading Image";
  78.  
  79. struct NewMenu TSMorphNewMenu[] = {
  80.     NM_TITLE, (STRPTR)NULL, NULL, 0, NULL, NULL,                            // 0
  81.     NM_ITEM, (STRPTR)NULL, (STRPTR)NULL, 0, 0L, (APTR)TSMorphMenuNew,            // 1
  82.     NM_ITEM, (STRPTR)NULL, (STRPTR)NULL, 0, 0L, (APTR)TSMorphMenuOpen,        // 2
  83.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,                            // 3
  84.     NM_ITEM, (STRPTR)NULL, (STRPTR)NULL, 0, 0L, (APTR)TSMorphMenuSave,            // 4
  85.     NM_ITEM, (STRPTR)NULL, (STRPTR)NULL, 0, 0L, (APTR)TSMorphMenuSaveAs,    // 5
  86.     NM_ITEM, (STRPTR)NULL, NULL, 0, 0L, (APTR)TSMorphMenuDelete,            // 6
  87.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,                            // 7
  88.     NM_ITEM, (STRPTR)NULL, NULL, 0, 0L, (APTR)TSMorphMenuAbout,            // 8
  89.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,                            // 9
  90.     NM_ITEM, (STRPTR)NULL, (STRPTR)NULL, 0, 0L, (APTR)TSMorphMenuQuit,            // 10
  91.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,                            // 11
  92.     NM_ITEM, (STRPTR)NULL,NULL,0,0L,(APTR)Preview,                        // 12
  93.     NM_ITEM, (STRPTR)NULL, (STRPTR)NULL, 0, 0L, (APTR)TSMorphMenuEditPoints,    // 13
  94.     NM_TITLE, (STRPTR)NULL, NULL, 0, NULL, NULL,                            // 14
  95. // Note this title has no items, these are based on the global settings menu
  96.     NM_END, NULL, NULL, 0, 0L, NULL };
  97.  
  98. UBYTE *SinglePictureLabels[] = {
  99.     (UBYTE *)"Morph",
  100.     (UBYTE *)"Warp",
  101.     (UBYTE *)"AMorph",
  102.     (UBYTE *)"AWarp",
  103.     NULL
  104. };
  105.  
  106. UWORD TSMorphGTypes[] = {
  107.     GENERIC_KIND,
  108.     GENERIC_KIND,
  109.     NUMBER_KIND,
  110.     NUMBER_KIND,
  111.     GENERIC_KIND,
  112.     GENERIC_KIND,
  113.     BUTTON_KIND,
  114.     CYCLE_KIND,
  115.     GENERIC_KIND,
  116.     STRING_KIND,
  117.     STRING_KIND,
  118.     STRING_KIND,
  119.     STRING_KIND,
  120.     INTEGER_KIND,
  121.     INTEGER_KIND,
  122.     STRING_KIND,
  123.     TEXT_KIND,
  124. };
  125.  
  126. struct NewGadget TSMorphNGad[] = {
  127.     239, 57, 20, 14, NULL, NULL, GD_GetFile1, 0, NULL, (APTR)GetFile1Clicked,
  128.     239, 75, 20, 14, NULL, NULL, GD_GetFile2, 0, NULL, (APTR)GetFile2Clicked,
  129.     72, 96, 37, 13, (UBYTE *)"Width", NULL, GD_Width, PLACETEXT_LEFT, NULL, NULL,
  130.     222, 96, 37, 13, (UBYTE *)"Height", NULL, GD_Height, PLACETEXT_LEFT, NULL, NULL,
  131.     239, 21, 20, 14, NULL, NULL, GD_GetFileOne, 0, NULL, (APTR)GetFileOneClicked,
  132.     239, 39, 20, 14, NULL, NULL, GD_GetFileTwo, 0, NULL, (APTR)GetFileTwoClicked,
  133.     2, 150, 257, 15, (UBYTE *)"Edit _Points...", NULL, GD_EditPoints, PLACETEXT_IN, NULL, (APTR)EditPointsClicked,
  134.     2, 114, 80, 14, NULL, NULL, GD_SinglePicture, 0, NULL, (APTR)SinglePictureClicked,
  135.     239, 132, 20, 14, NULL, NULL, GD_GetSaveName, 0, NULL, (APTR)GetSaveNameClicked,
  136.     72, 21, 163, 14, (UBYTE *)"File _One", NULL, GD_FileOne, PLACETEXT_LEFT, NULL, (APTR)FileOneClicked,
  137.     72, 39, 163, 14, (UBYTE *)"File _Two", NULL, GD_FileTwo, PLACETEXT_LEFT, NULL, (APTR)FileTwoClicked,
  138.     72, 57, 163, 14, (UBYTE *)"24 File _1", NULL, GD_File241, PLACETEXT_LEFT, NULL, (APTR)File241Clicked,
  139.     72, 75, 163, 14, (UBYTE *)"24 File _2", NULL, GD_File242, PLACETEXT_LEFT, NULL, (APTR)File242Clicked,
  140.     140, 114, 37, 14, (UBYTE *)"_Frames", NULL, GD_Frames, PLACETEXT_LEFT, NULL, (APTR)FramesClicked,
  141.     230, 114, 29, 14, (UBYTE *)"St_art", NULL, GD_Start, PLACETEXT_LEFT, NULL, (APTR)StartClicked,
  142.     72, 132, 163, 14, (UBYTE *)"_Name", NULL, GD_Name, PLACETEXT_LEFT, NULL, (APTR)NameClicked,
  143.     2, 4, 257, 13,NULL,NULL,GD_Help,0,NULL,NULL,
  144. };
  145.  
  146. ULONG TSMorphGTags[] = {
  147.     (TAG_DONE),
  148.     (TAG_DONE),
  149.     (GTNM_Border), TRUE, (TAG_DONE),
  150.     (GTNM_Border), TRUE, (TAG_DONE),
  151.     (TAG_DONE),
  152.     (TAG_DONE),
  153.     (GT_Underscore), '_', (TAG_DONE),
  154.     (GT_Underscore), '_', (GTCY_Labels), (ULONG)&SinglePictureLabels[0], (TAG_DONE),
  155.     (TAG_DONE),
  156.     (STRINGA_ExitHelp), TRUE, (GTST_MaxChars), 256, (STRINGA_Justification), (GACT_STRINGRIGHT), (GT_Underscore), '_', (TAG_DONE),
  157.     (STRINGA_ExitHelp), TRUE, (GTST_MaxChars), 256, (STRINGA_Justification), (GACT_STRINGRIGHT), (GT_Underscore), '_', (TAG_DONE),
  158.     (STRINGA_ExitHelp), TRUE, (GTST_MaxChars), 256, (STRINGA_Justification), (GACT_STRINGRIGHT), (GT_Underscore), '_', (TAG_DONE),
  159.     (STRINGA_ExitHelp), TRUE, (GTST_MaxChars), 256, (STRINGA_Justification), (GACT_STRINGRIGHT), (GT_Underscore), '_', (TAG_DONE),
  160.     (STRINGA_ExitHelp), TRUE,     (GTIN_Number), 1, (GTIN_MaxChars), 10, (GT_Underscore), '_', (TAG_DONE),
  161.     (STRINGA_ExitHelp), TRUE,     (GTIN_Number), 0, (GTIN_MaxChars), 10, (GT_Underscore), '_', (TAG_DONE),
  162.     (STRINGA_ExitHelp), TRUE,     (GTST_MaxChars), 256, (STRINGA_Justification), (GACT_STRINGRIGHT), (GT_Underscore), '_', (TAG_DONE),
  163.     (GTTX_Border), TRUE, (TAG_DONE),
  164. };
  165.  
  166. UWORD GridRequestGTypes[] = {
  167.     INTEGER_KIND,
  168.     INTEGER_KIND,
  169.     BUTTON_KIND,
  170.     BUTTON_KIND
  171. };
  172.  
  173. struct NewGadget GridRequestNGad[] = {
  174.     76, 5, 40, 14, (UBYTE *)"_X Cells", NULL, GD_XCells, PLACETEXT_LEFT, NULL, (APTR)XCellsClicked,
  175.     76, 23, 40, 14, (UBYTE *)"_Y Cells", NULL, GD_YCells, PLACETEXT_LEFT, NULL, (APTR)YCellsClicked,
  176.     6, 43, 52, 13, (UBYTE *)"_OK", NULL, GD_OK, PLACETEXT_IN, NULL, (APTR)OKClicked,
  177.     64, 43, 52, 13, (UBYTE *)"_Cancel", NULL, GD_Cancel, PLACETEXT_IN, NULL, (APTR)CancelClicked
  178. };
  179.  
  180. ULONG GridRequestGTags[] = {
  181.     (STRINGA_ExitHelp), TRUE, (GTIN_Number), 5, (GTIN_MaxChars), 3, (GT_Underscore), '_', (TAG_DONE),
  182.     (STRINGA_ExitHelp), TRUE, (GTIN_Number), 5, (GTIN_MaxChars), 3, (GT_Underscore), '_', (TAG_DONE),
  183.     (GT_Underscore), '_', (TAG_DONE),
  184.     (GT_Underscore), '_', (TAG_DONE)
  185. };
  186.  
  187. UWORD ProgressGTypes[] = {
  188.     TEXT_KIND,
  189.     SLIDER_KIND,
  190.     SLIDER_KIND
  191. };
  192.  
  193. struct NewGadget ProgressNGad[] = {
  194.     6, 6, 301, 13, NULL, NULL, GD_Mess, 0, NULL, NULL,
  195.     52, 26, 226, 11, (UBYTE *)"Pass", NULL, GD_Pass1, PLACETEXT_LEFT, NULL, NULL,
  196.     52, 43, 226, 11, (UBYTE *)"", NULL, GD_Pass2, PLACETEXT_LEFT, NULL, NULL
  197. };
  198.  
  199. ULONG ProgressGTags[] = {
  200.     (GTTX_Border), TRUE, (TAG_DONE),
  201.     (GTSL_Max), 1, (GTSL_Min), 1, (GTSL_Level), 1, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_RelVerify), TRUE, GA_Disabled,TRUE,(TAG_DONE),
  202.     (GTSL_Max), 999, (GTSL_Min), 0, (GTSL_MaxLevelLen), 4, (GTSL_LevelFormat), (ULONG)"%3ld", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_RelVerify), TRUE, GA_Disabled,TRUE,(TAG_DONE)
  203. };
  204.  
  205.  
  206. struct Rectangle    Rect[17];
  207. struct Rectangle    GRect[4];
  208.  
  209. // The compute font sizing stuff has been changed
  210. static UWORD ComputeX( UWORD value )
  211. {
  212.     return(( UWORD )((( FontX * value ) + 3 ) / 6 ));
  213. }
  214.  
  215. static UWORD ComputeY( UWORD value )
  216. {
  217.     return(( UWORD )((( FontY * value ) + 5 ) / 10 ));
  218. }
  219.  
  220. static void ComputeFont( UWORD width, UWORD height )
  221. {
  222.     Font = &Attr;
  223.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  224.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  225.     FontX = Scr->RastPort.Font->tf_XSize;
  226.  
  227.     OffX = Scr->WBorLeft;
  228.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  229.  
  230.     if ( width && height ) {
  231.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  232.             goto UseTopaz;
  233.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  234.             goto UseTopaz;
  235.     }
  236.     return;
  237.  
  238. UseTopaz:
  239.     Font->ta_Name = (STRPTR)"topaz.font";
  240.     FontX = FontY = Font->ta_YSize = 8;
  241. }
  242.  
  243. int SetupScreen( void )
  244. {
  245.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  246.         return( 1L );
  247.  
  248. // Is screen low or hires (this check is not really the correct method
  249. // but there does not appear to be a correct method - How does Workbench
  250. // do it? But at least it gets the scroll bars right on lo-res screens,
  251. // unlike MultiView!)
  252.     if (!(Scr->ViewPort.Modes & (HIRES | SUPERHIRES))) {
  253.         n=GS_LOWRES;
  254.     }
  255.        else {
  256.         n=GS_MEDRES;
  257.        }
  258.  
  259.     ComputeFont( 0, 0 );
  260.  
  261.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  262.         return( 2L );
  263.  
  264.     if ( ! ( getClass = initGet()))
  265.         return( 3L );
  266.  
  267.     if ( ! ( getImage = NewObject( getClass, NULL, GT_VisualInfo, VisualInfo, TAG_DONE )))
  268.         return( 4L );
  269.  
  270.     return( 0L );
  271. }
  272.  
  273. void CloseDownScreen( void )
  274. {
  275.     if ( getImage   ) {
  276.         DisposeObject( getImage );
  277.         getImage = NULL;
  278.     }
  279.  
  280.     if ( getClass   ) {
  281.         FreeClass( getClass );
  282.         getClass = NULL;
  283.     }
  284.  
  285.     if ( VisualInfo ) {
  286.         FreeVisualInfo( VisualInfo );
  287.         VisualInfo = NULL;
  288.     }
  289.  
  290.     if ( Scr        ) {
  291.         UnlockPubScreen( NULL, Scr );
  292.         Scr = NULL;
  293.     }
  294. }
  295. typedef int (FPTR(void));
  296. int HandleTSMorphIDCMP( void )
  297. {
  298.     struct IntuiMessage    *m;
  299.     struct MenuItem        *n;
  300.     int            (*func)(void);
  301.     BOOL            running = TRUE;
  302.     ULONG HNum;
  303.  
  304.     while( m = GT_GetIMsg( TSMorphWnd->UserPort )) {
  305.  
  306.         CopyMem(( char * )m, ( char * )&TSMorphMsg, (long)sizeof( struct IntuiMessage ));
  307.  
  308.         GT_ReplyIMsg( m );
  309.  
  310.         switch ( TSMorphMsg.Class ) {
  311.  
  312.             case    IDCMP_REFRESHWINDOW:
  313.                 GT_BeginRefresh( TSMorphWnd );
  314.                 GT_EndRefresh( TSMorphWnd, TRUE );
  315.                 break;
  316.  
  317.             case    IDCMP_CLOSEWINDOW:
  318.                 running = TSMorphCloseWindow();
  319.                 break;
  320.  
  321.             case    IDCMP_MENUHELP:
  322.                 running = TSMorphMenuHelp();
  323.                 break;
  324.  
  325.             case    IDCMP_VANILLAKEY:
  326.                 running = TSMorphVanillaKey();
  327.                 break;
  328.  
  329.             case    IDCMP_RAWKEY:
  330.                 running = TSMorphRawKey();
  331.                 break;
  332.  
  333.             case    IDCMP_GADGETUP:
  334.                 func = (FPTR *)(( struct Gadget * )TSMorphMsg.IAddress )->UserData;
  335.                 running = func();
  336.                 break;
  337.  
  338. // special case - settings use no GadToolsBox method
  339.             case    IDCMP_MENUPICK:
  340.                 while( TSMorphMsg.Code != MENUNULL ) {
  341.                     n = ItemAddress( TSMorphMenus, TSMorphMsg.Code );
  342.                     if (func = (FPTR *)(GTMENUITEM_USERDATA( n ))) {
  343.                         running = func();
  344.                     }
  345.                     else {
  346.                         HandleSettings(TSMorphMsg.Code,NULL);
  347.                     }
  348.                     TSMorphMsg.Code = n->NextSelect;
  349.                 }
  350.                 break;
  351.  
  352. // special case GadgetHelp
  353. // see the amigaguide distribution for some of how
  354. // this stuff works (i.e. do not ask me, I am not a developer)
  355.             case    IDCMP_GADGETHELP:
  356.                  if (TSMorphMsg.IAddress == NULL) {
  357.                      HNum = 0;
  358.                  }
  359.                  else {
  360.                      if (TSMorphMsg.IAddress == TSMorphWnd) {
  361.                          HNum = H_IWindow;
  362.                      }
  363.                      else {
  364.                          switch (((struct Gadget *)TSMorphMsg.IAddress)->GadgetType &0xf0) {
  365.                          case GTYP_WDRAGGING:
  366.                              HNum = H_IWindow;
  367.                              break;
  368.                          case GTYP_WUPFRONT:
  369.                              HNum = H_IDepth;
  370.                              break;
  371.                          case GTYP_WDOWNBACK:
  372.                              HNum = H_IZoom;
  373.                              break;
  374.                          case GTYP_CLOSE:
  375.                              HNum = H_IClose;
  376.                              break;
  377.                          case 0:
  378.                              switch (((struct Gadget *)TSMorphMsg.IAddress)->GadgetID) {
  379.                              case GD_Help:
  380.                                  HNum = H_HelpGad;
  381.                                  break;
  382.                              case GD_GetFile1:
  383.                                  HNum = H_G24File1;
  384.                                  break;
  385.                              case GD_GetFile2:
  386.                                  HNum = H_G24File2;
  387.                                  break;
  388.                              case GD_Width:
  389.                                  HNum = H_Width;
  390.                                  break;
  391.                              case GD_Height:
  392.                                  HNum = H_Height;
  393.                                  break;
  394.                              case GD_GetFileOne:
  395.                                  HNum = H_GFileOne;
  396.                                  break;
  397.                              case GD_GetFileTwo:
  398.                                  HNum = H_GFileTwo;
  399.                                  break;
  400.                              case GD_EditPoints:
  401.                                  HNum = H_EPoints;
  402.                                  break;
  403.                              case GD_SinglePicture:
  404.                                  HNum = H_Single;
  405.                                  break;
  406.                              case GD_GetSaveName:
  407.                                  HNum = H_GName;
  408.                                  break;
  409.                              case GD_FileOne:
  410.                                  HNum = H_FileOne;
  411.                                  break;
  412.                              case GD_FileTwo:
  413.                                  HNum = H_FileTwo;
  414.                                  break;
  415.                              case GD_File241:
  416.                                  HNum = H_24File1;
  417.                                  break;
  418.                              case GD_File242:
  419.                                  HNum = H_24File2;
  420.                                  break;
  421.                              case GD_Frames:
  422.                                  HNum = H_Frames;
  423.                                  break;
  424.                              case GD_Start:
  425.                                  HNum = H_Start;
  426.                                  break;
  427.                              case GD_Name:
  428.                                  HNum = H_Name;
  429.                                  break;
  430.                              default:
  431.                                  HNum = H_IWindow;
  432.                                  break;
  433.                              }
  434.                              break;
  435.                          default:
  436.                              HNum = H_IWindow;
  437.                              break;
  438.                          }
  439.                      }
  440.                  }
  441.                  if (HNum) {
  442.                      // display full or short help
  443.                      if (GHelp) {
  444.                          help(HNum);
  445.                      }
  446.                      else {
  447.                          ihelp(HNum);
  448.                      }
  449.                  }
  450.                 break;
  451.         }
  452.     }
  453.     return( (int) running );
  454. }
  455.  
  456. int OpenTSMorphWindow( void )
  457. {
  458.     struct NewGadget    ng;
  459.     struct Gadget    *g;
  460.     UWORD        lc, tc;
  461.     UWORD        wleft = TSMorphLeft, wtop, ww, wh;
  462.     TSMorphNewMenu[0].nm_Label = MyGetMsg(MSG_NM_PROJECT);
  463.     TSMorphNewMenu[1].nm_Label = MyGetMsg(MSG_NMT_NEW);
  464.     TSMorphNewMenu[1].nm_CommKey = MyGetMsg(MSG_NM_NEWPOINTS_S);
  465.     TSMorphNewMenu[2].nm_Label = MyGetMsg(MSG_NMT_OPEN);
  466.     TSMorphNewMenu[2].nm_CommKey = MyGetMsg(MSG_NM_OPENPOINTS_S);
  467.     TSMorphNewMenu[4].nm_Label = MyGetMsg(MSG_NM_SAVE);
  468.     TSMorphNewMenu[4].nm_CommKey = MyGetMsg(MSG_NM_SAVE_S);
  469.     TSMorphNewMenu[5].nm_Label = MyGetMsg(MSG_NM_SAVEAS);
  470.     TSMorphNewMenu[5].nm_CommKey = MyGetMsg(MSG_NM_SAVEAS_S);
  471.     TSMorphNewMenu[6].nm_Label = MyGetMsg(MSG_NMT_DELETE);
  472.     TSMorphNewMenu[8].nm_Label = MyGetMsg(MSG_NM_ABOUT);
  473.     TSMorphNewMenu[10].nm_Label = MyGetMsg(MSG_NM_QUIT);
  474.     TSMorphNewMenu[10].nm_CommKey = MyGetMsg(MSG_NM_QUIT_S);
  475.     TSMorphNewMenu[12].nm_Label = MyGetMsg(MSG_NM_PPREVIEW);
  476.     TSMorphNewMenu[13].nm_Label = MyGetMsg(MSG_NMT_EDITPOINTS);
  477.     TSMorphNewMenu[13].nm_CommKey = MyGetMsg(MSG_NMT_EDITPOINTS_S);
  478.     TSMorphNewMenu[14].nm_Label = MyGetMsg(MSG_NM_SETTINGS);
  479.  
  480.     MyNewMenu[NM_PROJECT].nm_Label = MyGetMsg(MSG_NM_PROJECT);
  481.     MyNewMenu[NM_NEWPOINTS].nm_Label = MyGetMsg(MSG_NM_NEWPOINTS);
  482.     MyNewMenu[NM_NEWPOINTS].nm_CommKey = MyGetMsg(MSG_NM_NEWPOINTS_S);
  483.     MyNewMenu[NM_OPENPOINTS].nm_Label = MyGetMsg(MSG_NM_OPENPOINTS);
  484.     MyNewMenu[NM_OPENPOINTS].nm_CommKey = MyGetMsg(MSG_NM_OPENPOINTS_S);
  485.     MyNewMenu[NM_SAVE].nm_Label = MyGetMsg(MSG_NM_SAVE);
  486.     MyNewMenu[NM_SAVE].nm_CommKey = MyGetMsg(MSG_NM_SAVE_S);
  487.     MyNewMenu[NM_SAVEAS].nm_Label = MyGetMsg(MSG_NM_SAVEAS);
  488.     MyNewMenu[NM_SAVEAS].nm_CommKey = MyGetMsg(MSG_NM_SAVEAS_S);
  489.     MyNewMenu[NM_ABOUT].nm_Label = MyGetMsg(MSG_NM_ABOUT);
  490.     MyNewMenu[NM_EXITPOINTS].nm_Label = MyGetMsg(MSG_NM_EXITPOINTS);
  491.     MyNewMenu[NM_QUIT].nm_Label = MyGetMsg(MSG_NM_QUIT);
  492.     MyNewMenu[NM_QUIT].nm_CommKey = MyGetMsg(MSG_NM_QUIT_S);
  493.     MyNewMenu[NM_PPREVIEW].nm_Label = MyGetMsg(MSG_NM_PPREVIEW);
  494.     MyNewMenu[NM_EDIT].nm_Label = MyGetMsg(MSG_NM_EDIT);
  495.     MyNewMenu[NM_ADDGRID].nm_Label = MyGetMsg(MSG_NM_ADDGRID);
  496.     MyNewMenu[NM_ADDGRID].nm_CommKey = MyGetMsg(MSG_NM_ADDGRID_S);
  497.     MyNewMenu[NM_TRIANGULATE].nm_Label = MyGetMsg(MSG_NM_TRIANGULATE);
  498.     MyNewMenu[NM_TRIANGULATE].nm_CommKey = MyGetMsg(MSG_NM_TRIANGULATE_S);
  499.     MyNewMenu[NM_FRAME].nm_Label = MyGetMsg(MSG_NM_FRAME);
  500.     MyNewMenu[NM_FIRST].nm_Label = MyGetMsg(MSG_NM_FIRST);
  501.     MyNewMenu[NM_FIRST].nm_CommKey = MyGetMsg(MSG_NM_FIRST_S);
  502.     MyNewMenu[NM_PREVIOUS].nm_Label = MyGetMsg(MSG_NM_PREVIOUS);
  503.     MyNewMenu[NM_PREVIOUS].nm_CommKey = MyGetMsg(MSG_NM_PREVIOUS_S);
  504.     MyNewMenu[NM_GOTO].nm_Label = MyGetMsg(MSG_NM_GOTO);
  505.     MyNewMenu[NM_GOTO].nm_CommKey = MyGetMsg(MSG_NM_GOTO_S);
  506.     MyNewMenu[NM_NEXT].nm_Label = MyGetMsg(MSG_NM_NEXT);
  507.     MyNewMenu[NM_NEXT].nm_CommKey = MyGetMsg(MSG_NM_NEXT_S);
  508.     MyNewMenu[NM_LAST].nm_Label = MyGetMsg(MSG_NM_LAST);
  509.     MyNewMenu[NM_LAST].nm_CommKey = MyGetMsg(MSG_NM_LAST_S);
  510.     MyNewMenu[NM_EMODE].nm_Label = MyGetMsg(MSG_NM_EMODE);
  511.     MyNewMenu[NM_M_ONE].nm_Label = MyGetMsg(MSG_NM_M_ONE);
  512.     MyNewMenu[NM_M_ONE].nm_CommKey = MyGetMsg(MSG_NM_M_ONE_S);
  513.     MyNewMenu[NM_M_TWO].nm_Label = MyGetMsg(MSG_NM_M_TWO);
  514.     MyNewMenu[NM_M_TWO].nm_CommKey = MyGetMsg(MSG_NM_M_TWO_S);
  515.     MyNewMenu[NM_M_REL].nm_Label = MyGetMsg(MSG_NM_M_REL);
  516.     MyNewMenu[NM_M_REL].nm_CommKey = MyGetMsg(MSG_NM_M_REL_S);
  517.     MyNewMenu[NM_M_ADD].nm_Label = MyGetMsg(MSG_NM_M_ADD);
  518.     MyNewMenu[NM_M_ADD].nm_CommKey = MyGetMsg(MSG_NM_M_ADD_S);
  519.     MyNewMenu[NM_M_DEL].nm_Label = MyGetMsg(MSG_NM_M_DEL);
  520.     MyNewMenu[NM_M_DEL].nm_CommKey = MyGetMsg(MSG_NM_M_DEL_S);
  521.     MyNewMenu[NM_M_LNK].nm_Label = MyGetMsg(MSG_NM_M_LNK);
  522.     MyNewMenu[NM_M_LNK].nm_CommKey = MyGetMsg(MSG_NM_M_LNK_S);
  523.     MyNewMenu[NM_M_UNL].nm_Label = MyGetMsg(MSG_NM_M_UNL);
  524.     MyNewMenu[NM_M_UNL].nm_CommKey = MyGetMsg(MSG_NM_M_UNL_S);
  525.     MyNewMenu[NM_M_MOV].nm_Label = MyGetMsg(MSG_NM_M_MOV);
  526.     MyNewMenu[NM_M_MOV].nm_CommKey = MyGetMsg(MSG_NM_M_MOV_S);
  527.     MyNewMenu[NM_SETTINGS].nm_Label = MyGetMsg(MSG_NM_SETTINGS);
  528.     MyNewMenu[NM_CREATEICONS].nm_Label = MyGetMsg(MSG_NM_CREATEICONS);
  529.     MyNewMenu[NM_CHANGEPALETTE].nm_Label = MyGetMsg(MSG_NM_CHANGEPALETTE);
  530.     MyNewMenu[NM_CHANGEPALETTE].nm_CommKey = MyGetMsg(MSG_NM_CHANGEPALETTE_S);
  531.     MyNewMenu[NM_ZOOM].nm_Label = MyGetMsg(MSG_NM_ZOOM);
  532.     MyNewMenu[NM_ZOOM].nm_CommKey = MyGetMsg(MSG_NM_ZOOM_S);
  533.     MyNewMenu[NM_OPENMODE].nm_Label = MyGetMsg(MSG_NM_OPENMODE);
  534.     MyNewMenu[NM_ILBMALWAYS].nm_Label = MyGetMsg(MSG_NM_ILBMALWAYS);
  535.     MyNewMenu[NM_ILBMIFILBM].nm_Label = MyGetMsg(MSG_NM_ILBMIFILBM);
  536.     MyNewMenu[NM_ILBMIFCOLOURS].nm_Label = MyGetMsg(MSG_NM_ILBMIFCOLOURS);
  537.     MyNewMenu[NM_REMAP].nm_Label = MyGetMsg(MSG_NM_REMAP);
  538.     MyNewMenu[NM_ILBMOPAL].nm_Label = MyGetMsg(MSG_NM_ILBMOPAL);
  539.     MyNewMenu[NM_SCREEN].nm_Label = MyGetMsg(MSG_NM_SCREEN);
  540.     MyNewMenu[NM_CUSTOM].nm_Label = MyGetMsg(MSG_NM_CUSTOM);
  541.     MyNewMenu[NM_CDEPTH].nm_Label = MyGetMsg(MSG_NM_CDEPTH);
  542.     MyNewMenu[NM_SPREVIEW].nm_Label = MyGetMsg(MSG_NM_SPREVIEW);
  543.     MyNewMenu[NM_ICONSP].nm_Label = MyGetMsg(MSG_NM_ICONSP);
  544.     MyNewMenu[NM_KEEPS].nm_Label = MyGetMsg(MSG_NM_KEEPS);
  545.     MyNewMenu[NM_LOADS].nm_Label = MyGetMsg(MSG_NM_LOADS);
  546.     MyNewMenu[NM_SAVES].nm_Label = MyGetMsg(MSG_NM_SAVES);
  547.     MyNewMenu[NM_SAVESAS].nm_Label = MyGetMsg(MSG_NM_SAVESAS);
  548.     MyNewMenu[NM_ICONSR].nm_Label = MyGetMsg(MSG_NM_ICONSR);
  549.     MyNewMenu[NM_DX].nm_Label = MyGetMsg(MSG_NM_DX);
  550.     MyNewMenu[NM_DY].nm_Label = MyGetMsg(MSG_NM_DY);
  551.     MyNewMenu[NM_LOADSCRIPT].nm_Label = MyGetMsg(MSG_NM_LOADSCRIPT);
  552.     MyNewMenu[NM_PRESCRIPT].nm_Label = MyGetMsg(MSG_NM_PRESCRIPT);
  553.     MyNewMenu[NM_POSTSCRIPT].nm_Label = MyGetMsg(MSG_NM_POSTSCRIPT);
  554.     MyNewMenu[NM_DEPTH].nm_Label = MyGetMsg(MSG_NM_DEPTH);
  555.     MyNewMenu[NM_MODE].nm_Label = MyGetMsg(MSG_NM_MODE);
  556.     MyNewMenu[NM_MODE1].nm_Label = MyGetMsg(MSG_NM_MODE1);
  557.     MyNewMenu[NM_MODE2].nm_Label = MyGetMsg(MSG_NM_MODE2);
  558.     MyNewMenu[NM_MODE4].nm_Label = MyGetMsg(MSG_NM_MODE4);
  559.     MyNewMenu[NM_MODE8].nm_Label = MyGetMsg(MSG_NM_MODE8);
  560.     MyNewMenu[NM_MODE16].nm_Label = MyGetMsg(MSG_NM_MODE16);
  561.     MyNewMenu[NM_SAVEFORMAT].nm_Label = MyGetMsg(MSG_NM_SAVEFORMAT);
  562.     MyNewMenu[NM_ILBM24].nm_Label = MyGetMsg(MSG_NM_ILBM24);
  563.     MyNewMenu[NM_OPAL24].nm_Label = MyGetMsg(MSG_NM_OPAL24);
  564.     MyNewMenu[NM_OPAL24T].nm_Label = MyGetMsg(MSG_NM_OPAL24T);
  565.     MyNewMenu[NM_OPAL24F].nm_Label = MyGetMsg(MSG_NM_OPAL24F);
  566.     MyNewMenu[NM_OPAL24FT].nm_Label = MyGetMsg(MSG_NM_OPAL24FT);
  567.     MyNewMenu[NM_OPALJPEG].nm_Label = MyGetMsg(MSG_NM_OPALJPEG);
  568.     MyNewMenu[NM_OPALJPEGT].nm_Label = MyGetMsg(MSG_NM_OPALJPEGT);
  569.     MyNewMenu[NM_PBM].nm_Label = MyGetMsg(MSG_NM_PBM);
  570.     MyNewMenu[NM_BW16].nm_Label = MyGetMsg(MSG_NM_BW16);
  571.     MyNewMenu[NM_BW256].nm_Label = MyGetMsg(MSG_NM_BW256);
  572.     MyNewMenu[NM_HAM6].nm_Label = MyGetMsg(MSG_NM_HAM6);
  573.     MyNewMenu[NM_HAM8].nm_Label = MyGetMsg(MSG_NM_HAM8);
  574.     MyNewMenu[NM_DCTV3].nm_Label = MyGetMsg(MSG_NM_DCTV3);
  575.     MyNewMenu[NM_DCTV4].nm_Label = MyGetMsg(MSG_NM_DCTV4);
  576.     MyNewMenu[NM_QUALITY].nm_Label = MyGetMsg(MSG_NM_QUALITY);
  577.     MyNewMenu[NM_SCREENR].nm_Label = MyGetMsg(MSG_NM_SCREENR);
  578.     MyNewMenu[NM_ANTIALIAS].nm_Label = MyGetMsg(MSG_NM_ANTIALIAS);
  579.     MyNewMenu[NM_INTEGER].nm_Label = MyGetMsg(MSG_NM_INTEGER);
  580.     MyNewMenu[NM_RESETD].nm_Label = MyGetMsg(MSG_NM_RESETD);
  581.     MyNewMenu[NM_LASTS].nm_Label = MyGetMsg(MSG_NM_LASTS);
  582.     MyNewMenu[NM_RESTORE].nm_Label = MyGetMsg(MSG_NM_RESTORE);
  583.     MyNewMenu[NM_HELP].nm_Label = MyGetMsg(MSG_NM_HELP);
  584.     TSMorphTop = Scr->BarHeight + 1;
  585.     wtop = TSMorphTop;
  586.     ComputeFont( TSMorphWidth, TSMorphHeight );
  587.  
  588.     ww = ComputeX( TSMorphWidth );
  589.     wh = ComputeY( TSMorphHeight );
  590.  
  591.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  592.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  593.  
  594.     if ( ! ( g = CreateContext( &TSMorphGList )))
  595.         return( 1L );
  596.  
  597.  
  598. // If no reqtools then no animated morphs (so remove from cycle gadget)
  599. // purely because we need the Frame requester
  600.     if (!ReqToolsBase) {
  601.         SinglePictureLabels[2] = NULL;
  602.     }
  603.  
  604.     for( lc = 0, tc = 0; lc < TSMorph_CNT; lc++ ) {
  605.  
  606.         CopyMem((char * )&TSMorphNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  607.  
  608.         ng.ng_VisualInfo = VisualInfo;
  609.         ng.ng_TextAttr   = Font;
  610.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  611.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  612.  
  613.         if ( TSMorphGTypes[ lc ] != GENERIC_KIND ) {
  614.             ng.ng_Width      = ComputeX( ng.ng_Width );
  615.             ng.ng_Height     = ComputeY( ng.ng_Height);
  616.         }
  617.  
  618. // Save gadget position/size for help key
  619.         Rect[lc].MinX = ng.ng_LeftEdge;
  620.         Rect[lc].MinY = ng.ng_TopEdge;
  621.         Rect[lc].MaxX = ng.ng_LeftEdge + ng.ng_Width;
  622.         Rect[lc].MaxY = ng.ng_TopEdge + ng.ng_Height;
  623.  
  624.         TSMorphGadgets[ lc ] = g = CreateGadgetA((ULONG)TSMorphGTypes[ lc ], g, &ng, ( struct TagItem * )&TSMorphGTags[ tc ] );
  625.  
  626.         if ( TSMorphGTypes[ lc ] == GENERIC_KIND ) {
  627.             g->Flags             |= GFLG_GADGIMAGE | GFLG_GADGHIMAGE;
  628.             g->Activation        |= GACT_RELVERIFY;
  629.             g->GadgetRender       = (APTR)getImage;
  630.             g->SelectRender       = (APTR)getImage;
  631.         }
  632.  
  633.         while( TSMorphGTags[ tc ] ) tc += 2;
  634.         tc++;
  635.  
  636.         if ( NOT g )
  637.             return( 2L );
  638.     }
  639.  
  640. // update menus based on current settings
  641.     UpdateMenuDefs();
  642.  
  643. // non standard stuff, the settings menu is set up based on the global settings menu items
  644.     if ( ! ( TSMorphMenus = CreateMenus( TSMorphNewMenu, TAG_DONE )))
  645.         return( 3L );
  646.  
  647.     if ( ! ( TSMorphMenus1 = (struct MenuItem *)CreateMenus( &(MyNewMenu[NM_CREATEICONS]) , TAG_DONE )))
  648.         return( 3L );
  649.  
  650.     LayoutMenus( TSMorphMenus, VisualInfo, 
  651.                 GTMN_NewLookMenus,TRUE,
  652.                 TAG_DONE );
  653.  
  654.     TSMorphMenus->NextMenu->FirstItem = TSMorphMenus1;
  655.  
  656.     LayoutMenuItems(TSMorphMenus1, VisualInfo,
  657.                 GTMN_Menu,TSMorphMenus->NextMenu,
  658.                 GTMN_NewLookMenus,TRUE,
  659.                 TAG_DONE );
  660.  
  661.     TSMorphZoom[0] = TSMorphZoom[1] = 0;
  662.     TSMorphZoom[2]  = ww + OffX + Scr->WBorRight;
  663.     TSMorphZoom[3] = Rect[GDX_Help].MaxY + Scr->WBorBottom + 2;
  664. #define GADGETUP IDCMP_GADGETUP
  665. // This is used in the 2.02 versions of BUTTONIDCMP etc.
  666. // But is not defined as IOBSOLETE stuff is not included
  667.     if ( ! ( TSMorphWnd = OpenWindowTags( NULL,
  668.                 WA_Left,    wleft,
  669.                 WA_Top,        wtop,
  670.                 WA_Width,    ww + OffX + Scr->WBorRight,
  671.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  672.                 WA_IDCMP,    IDCMP_GADGETUP|NUMBERIDCMP|BUTTONIDCMP|CHECKBOXIDCMP|STRINGIDCMP|
  673.                             INTEGERIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_VANILLAKEY|
  674.                             IDCMP_MENUHELP|IDCMP_REFRESHWINDOW|IDCMP_GADGETHELP|IDCMP_MOUSEMOVE,
  675.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH,
  676.                 WA_Gadgets,    TSMorphGList,
  677.                 WA_Title,    TSMorphWdt,
  678.                 WA_ScreenTitle,    "TSMorph ©1993/94 Topicsave Limited",
  679.                 WA_PubScreen,    Scr,
  680.                 WA_Zoom,    TSMorphZoom,
  681.                 WA_AutoAdjust,    TRUE,
  682.                 WA_PubScreenFallBack,    TRUE,
  683.                 WA_MenuHelp,    TRUE,
  684.                 WA_NewLookMenus,TRUE,
  685.                 TAG_DONE )))
  686.     return( 4L );
  687.  
  688. // switch on gadget help if release 3.0+
  689.     if (IntuitionBase->LibNode.lib_Version > 38) {
  690.         HelpControl(TSMorphWnd,HC_GADGETHELP);
  691.     }
  692.  
  693.     SetMenuStrip( TSMorphWnd, TSMorphMenus );
  694.     GT_RefreshWindow( TSMorphWnd, NULL );
  695.  
  696.     ScreenToFront(Scr);
  697.  
  698.     return( 0L );
  699. }
  700.  
  701. void CloseTSMorphWindow( void )
  702. {
  703. // Free menus - not entirely sure if need (or should) do in two bits
  704.     if ( TSMorphMenus      ) {
  705.         if (TSMorphWnd) {
  706.             ClearMenuStrip( TSMorphWnd );
  707.         }
  708.         TSMorphMenus->NextMenu->FirstItem = NULL;
  709.         FreeMenus( TSMorphMenus );
  710.         TSMorphMenus = NULL;
  711.     }
  712.  
  713.     if (TSMorphMenus1) {
  714.         FreeMenus( (struct Menu *)TSMorphMenus1 );
  715.         TSMorphMenus1 = NULL;
  716.     }
  717.  
  718.     if ( TSMorphWnd        ) {
  719.         CloseWindow( TSMorphWnd );
  720.         TSMorphWnd = NULL;
  721.     }
  722.  
  723.     if ( TSMorphGList      ) {
  724.         FreeGadgets( TSMorphGList );
  725.         TSMorphGList = NULL;
  726.     }
  727. }
  728.  
  729. int HandleGridRequestIDCMP( void )
  730. {
  731.     struct IntuiMessage    *m;
  732.     int            (*func)(void);
  733.     BOOL            running = TRUE;
  734.     ULONG HNum;
  735.  
  736.     while( m = GT_GetIMsg( GridRequestWnd->UserPort )) {
  737.  
  738.         CopyMem(( char * )m, ( char * )&GridRequestMsg, (long)sizeof( struct IntuiMessage ));
  739.  
  740.         GT_ReplyIMsg( m );
  741.  
  742.         switch ( GridRequestMsg.Class ) {
  743.  
  744.             case    IDCMP_REFRESHWINDOW:
  745.                 GT_BeginRefresh( GridRequestWnd );
  746.                 GT_EndRefresh( GridRequestWnd, TRUE );
  747.                 break;
  748.  
  749.             case    IDCMP_CLOSEWINDOW:
  750.                 running = GridRequestCloseWindow();
  751.                 break;
  752.  
  753.             case    IDCMP_VANILLAKEY:
  754.                 running = GridRequestVanillaKey();
  755.                 break;
  756.  
  757.             case    IDCMP_RAWKEY:
  758.                 running = GridRequestRawKey();
  759.                 break;
  760.  
  761.             case    IDCMP_GADGETUP:
  762.                 func = (FPTR *)(( struct Gadget * )GridRequestMsg.IAddress )->UserData;
  763.                 running = func();
  764.                 break;
  765.  
  766. // gadgethelp - see above
  767.             case    IDCMP_GADGETHELP:
  768.                  if (GridRequestMsg.IAddress == NULL) {
  769.                      HNum = 0;
  770.                  }
  771.                  else {
  772.                      if (GridRequestMsg.IAddress == GridRequestWnd) {
  773.                          HNum = H_RAG;
  774.                      }
  775.                      else {
  776.                          switch (((struct Gadget *)GridRequestMsg.IAddress)->GadgetType &0xf0) {
  777.                          case GTYP_WDRAGGING:
  778.                              HNum = H_RAG;
  779.                              break;
  780.                          case GTYP_WUPFRONT:
  781.                              HNum = H_RAGGDE;
  782.                              break;
  783.                          case GTYP_CLOSE:
  784.                              HNum = H_RAGGCL;
  785.                              break;
  786.                          case 0:
  787.                              switch (((struct Gadget *)GridRequestMsg.IAddress)->GadgetID) {
  788.                              case GD_XCells:
  789.                                  HNum = H_RAGGX;
  790.                                  break;
  791.                              case GD_YCells:
  792.                                  HNum = H_RAGGY;
  793.                                  break;
  794.                              case GD_OK:
  795.                                  HNum = H_RAGGOK;
  796.                                  break;
  797.                              case GD_Cancel:
  798.                                  HNum = H_RAGGCA;
  799.                                  break;
  800.                              default:
  801.                                  HNum = H_RAG;
  802.                                  break;
  803.                              }
  804.                              break;
  805.                          default:
  806.                              HNum = H_RAG;
  807.                              break;
  808.                          }
  809.                      }
  810.                  }
  811.                  if (HNum) {
  812.                      if (GHelp) {
  813.                          help(HNum);
  814.                      }
  815.                      else {
  816.                          ihelp(HNum);
  817.                      }
  818.                  }
  819.                 break;
  820.         }
  821.     }
  822.     return( (int) running );
  823. }
  824.  
  825. int OpenGridRequestWindow( void )
  826. {
  827.     struct NewGadget    ng;
  828.     struct Gadget    *g;
  829.     UWORD        lc, tc;
  830.     UWORD        wleft = GridRequestLeft, wtop = GridRequestTop, ww, wh;
  831.  
  832.     ComputeFont( GridRequestWidth, GridRequestHeight );
  833.  
  834.     ww = ComputeX( GridRequestWidth );
  835.     wh = ComputeY( GridRequestHeight );
  836.  
  837.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  838.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  839.  
  840.     if ( ! ( g = CreateContext( &GridRequestGList )))
  841.         return( 1L );
  842.  
  843.     for( lc = 0, tc = 0; lc < GridRequest_CNT; lc++ ) {
  844.  
  845.         CopyMem((char * )&GridRequestNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  846.  
  847.         ng.ng_VisualInfo = VisualInfo;
  848.         ng.ng_TextAttr   = Font;
  849.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  850.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  851.         ng.ng_Width      = ComputeX( ng.ng_Width );
  852.         ng.ng_Height     = ComputeY( ng.ng_Height);
  853.  
  854. // save position and size for help key
  855.         GRect[lc].MinX = ng.ng_LeftEdge;
  856.         GRect[lc].MinY = ng.ng_TopEdge;
  857.         GRect[lc].MaxX = ng.ng_LeftEdge + ng.ng_Width;
  858.         GRect[lc].MaxY = ng.ng_TopEdge + ng.ng_Height;
  859.  
  860.         GridRequestGadgets[ lc ] = g = CreateGadgetA((ULONG)GridRequestGTypes[ lc ], g, &ng, ( struct TagItem * )&GridRequestGTags[ tc ] );
  861.  
  862.         while( GridRequestGTags[ tc ] ) tc += 2;
  863.         tc++;
  864.  
  865.         if ( NOT g )
  866.             return( 2L );
  867.     }
  868.  
  869.     if ( ! ( GridRequestWnd = OpenWindowTags( NULL,
  870.                 WA_Left,    wleft,
  871.                 WA_Top,        wtop,
  872.                 WA_Width,    ww + OffX + Scr->WBorRight,
  873.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  874.                 WA_IDCMP,    INTEGERIDCMP|BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_RAWKEY|IDCMP_VANILLAKEY|
  875.                             IDCMP_REFRESHWINDOW|IDCMP_GADGETHELP|IDCMP_MOUSEMOVE,
  876.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  877.                 WA_Gadgets,    GridRequestGList,
  878.                 WA_Title,    GridRequestWdt,
  879.                 WA_ScreenTitle,    "TSMorph",
  880.                 WA_PubScreen,    Scr,
  881.                 WA_AutoAdjust,    TRUE,
  882.                 TAG_DONE )))
  883.     return( 4L );
  884.  
  885. // switch on help control if release 3.0+
  886.     if (IntuitionBase->LibNode.lib_Version > 38) {
  887.         HelpControl(GridRequestWnd,HC_GADGETHELP);
  888.     }
  889.  
  890.     GT_RefreshWindow( GridRequestWnd, NULL );
  891.  
  892.     return( 0L );
  893. }
  894.  
  895. void CloseGridRequestWindow( void )
  896. {
  897.     if ( GridRequestWnd        ) {
  898.         CloseWindow( GridRequestWnd );
  899.         GridRequestWnd = NULL;
  900.     }
  901.  
  902.     if ( GridRequestGList      ) {
  903.         FreeGadgets( GridRequestGList );
  904.         GridRequestGList = NULL;
  905.     }
  906. }
  907.  
  908. int HandleProgressIDCMP( void )
  909. {
  910.     struct IntuiMessage    *m;
  911.     BOOL            running = TRUE;
  912.  
  913.     while( m = GT_GetIMsg( ProgressWnd->UserPort )) {
  914.  
  915.         CopyMem(( char * )m, ( char * )&ProgressMsg, (long)sizeof( struct IntuiMessage ));
  916.  
  917.         GT_ReplyIMsg( m );
  918.  
  919.         switch ( ProgressMsg.Class ) {
  920.  
  921.             case    IDCMP_REFRESHWINDOW:
  922.                 GT_BeginRefresh( ProgressWnd );
  923.                 GT_EndRefresh( ProgressWnd, TRUE );
  924.                 break;
  925.  
  926.         }
  927.     }
  928.     return( (int) running );
  929. }
  930.  
  931. int OpenProgressWindow( void )
  932. {
  933.     struct NewGadget    ng;
  934.     struct Gadget    *g;
  935.     UWORD        lc, tc;
  936.     UWORD        wleft = ProgressLeft, wtop = ProgressTop, ww, wh;
  937.  
  938.     ComputeFont( ProgressWidth, ProgressHeight );
  939.  
  940.     ww = ComputeX( ProgressWidth );
  941.     wh = ComputeY( ProgressHeight );
  942.  
  943.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  944.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  945.  
  946.     if ( ! ( g = CreateContext( &ProgressGList )))
  947.         return( 1L );
  948.  
  949.     for( lc = 0, tc = 0; lc < Progress_CNT; lc++ ) {
  950.  
  951.         CopyMem((char * )&ProgressNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  952.  
  953.         ng.ng_VisualInfo = VisualInfo;
  954.         ng.ng_TextAttr   = Font;
  955.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  956.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  957.         ng.ng_Width      = ComputeX( ng.ng_Width );
  958.         ng.ng_Height     = ComputeY( ng.ng_Height);
  959.  
  960.         ProgressGadgets[ lc ] = g = CreateGadgetA((ULONG)ProgressGTypes[ lc ], g, &ng, ( struct TagItem * )&ProgressGTags[ tc ] );
  961.  
  962.         while( ProgressGTags[ tc ] ) tc += 2;
  963.         tc++;
  964.  
  965.         if ( NOT g )
  966.             return( 2L );
  967.     }
  968.  
  969.     if ( ! ( ProgressWnd = OpenWindowTags( NULL,
  970.                 WA_Left,    wleft,
  971.                 WA_Top,        wtop,
  972.                 WA_Width,    ww + OffX + Scr->WBorRight,
  973.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  974.                 WA_IDCMP,    TEXTIDCMP|IDCMP_REFRESHWINDOW,
  975.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_SMART_REFRESH,
  976.                 WA_Gadgets,    ProgressGList,
  977.                 WA_Title,    ProgressWdt,
  978.                 WA_ScreenTitle,    "TSMorph ©1993/94 Topicsave Limited",
  979.                 WA_PubScreen,    Scr,
  980.                 TAG_DONE )))
  981.     return( 4L );
  982.  
  983. // Wait pointer
  984.     SetPointer(ProgressWnd, BusyPointerData, 16, 16, -6, 0);
  985.     GT_RefreshWindow( ProgressWnd, NULL );
  986.  
  987.     return( 0L );
  988. }
  989.  
  990. void CloseProgressWindow( void )
  991. {
  992.     if ( ProgressWnd        ) {
  993.         CloseWindow( ProgressWnd );
  994.         ProgressWnd = NULL;
  995.     }
  996.  
  997.     if ( ProgressGList      ) {
  998.         FreeGadgets( ProgressGList );
  999.         ProgressGList = NULL;
  1000.     }
  1001. }
  1002.  
  1003.